const Mock = require('mockjs')

const List = []
const count = 100

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
  id: '@increment',
  date: '@datetime',
  'messageGroup|1': ['PLC_1','PLC_2'],
  'messageType|1': ['信息','警告','故障'],
  description: '@title(5, 20)',
  }))
}


module.exports = [
  // {
  //   url: '/table/getWriteList',
  //   type: 'get',
  //   response: config => {
  //     return {
  //       code: 20000,
  //       data: {
  //         total: List.length,
  //         items: List
  //       }
  //     }
  //   }
  // },
  {
    url: '/event/getEventList',
    type: 'get',
    response: config => {
      const {  date,messageGroup,messageType, page = 1, limit = 20, sort } = config.query
      let mockList = List.filter(item => {

        // console.log(date)
        if (messageGroup && item.messageGroup !== messageGroup) return false
        if (messageType && item.messageType.indexOf(messageType) < 0) return false

        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },
]

